Articles in this section
Category / Section

How to make GridControl behave like ListBox in Winforms?

4 mins read

Description

Need to make WinForms GridControl work like a ListBox.

 

Solution

You need to do two things to make the GridControl work like a ListBox. To achieve this requirement, you need to change the ListBoxSelectionMode and explicitly set the column index to 0 by using the currentCellMoving and CurrentCellActivating events.

The following code examples are for changing ListBoxSelectionMode.

// Changing the GridControlSelectionMode
this.gridControl1.ListBoxSelectionMode = SelectionMode.One;
'Changing the GridControlSelectionMode
Me.gridControl1.ListBoxSelectionMode = SelectionMode.One

The following code example is for setting the column index to 0.

private void gridControl1_CurrentCellMoving(object sender, GridCurrentCellMovingEventArgs e)
{
  e.ColIndex = 0;
}

private void gridControl1_CurrentCellActivating(object sender, GridCurrentCellActivatingEventArgs e)
{
   e.ColIndex = 0;
}
Private Sub gridControl1_CurrentCellMoving(ByVal sender As Object, ByVal e As GridCurrentCellMovingEventArgs)
   e.ColIndex = 0
End Sub

Private Sub gridControl1_CurrentCellActivating(ByVal sender As Object, ByVal e As GridCurrentCellActivatingEventArgs)
   e.ColIndex = 0
End Sub

The following screenshot is for GridControl without CurrentCell selection.

Selecting the row on clicking a cell without showing current cell in WinForms GridControl


 Figure
1: Selecting the row on clicking a cell without showing current cell

Sample:

C#: GridControl like ListBox CS

VB: GridControl like ListBox VB

 

Conclusion


I hope you enjoyed learning about how to make GridControl behave like ListBox in Winforms.


You can refer to our WinForms GridControl feature tour page to know about its other groundbreaking feature representations and WinForms GridControl documentation, and how to quickly get started for configuration specifications.


For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.


If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied